home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1993 by Michael Davidson.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software
- * and its documentation for any purpose and without fee is hereby
- * granted, provided that the above copyright notice appear in all
- * copies and that both that copyright notice and this permission
- * notice appear in supporting documentation.
- *
- * This software is provided "as is" without express or implied warranty.
- */
-
- #include <stdio.h>
- #include "vg.h"
- #include "video.h"
- #include "kbd.h"
-
- STATIC int test0();
- STATIC int test1();
-
- STATIC int (*Tests[])() =
- {
- test0,
- test1,
- 0
- };
-
- STATIC color_t TestColorMap[256];
- STATIC int TestMode;
- STATIC vmode_t *TestModeInfo;
- STATIC char TestInfo[40];
-
- void
- testInitColorMap()
- {
- color_t *c;
- int v;
-
- for (v = 0, c = TestColorMap; v < 256; v += 4, c++)
- {
- c[0].red = v; c[0].green = 0; c[0].blue = 0;
- c[64].red = 0; c[64].green = v; c[64].blue = 0;
- c[128].red = 0; c[128].green = 0; c[128].blue = v;
- c[192].red = v; c[192].green = v; c[192].blue = v;
- }
- }
-
- #define SUPPORTED_GRAPHICS_MODE(m) \
- ( ((m)->flags & (V_MODE_SUPPORTED | V_GRAPHICS_MODE)) \
- == (V_MODE_SUPPORTED | V_GRAPHICS_MODE) )
- void
- testMenu()
- {
- vmode_t *modes;
- vmode_t *m;
- int r;
-
- testInitColorMap();
-
- modes = vidGetModes();
-
- /*
- * find first supported mode
- */
- for (m = modes; m->flags != 0; m++)
- if (SUPPORTED_GRAPHICS_MODE(m))
- break;
-
- while (m >= modes && m->flags != 0)
- {
- TestMode = m - modes;
- TestModeInfo = m;
-
- r = testExecute();
-
- switch (r)
- {
- case F_NEXT:
- while ((++m)->flags != 0)
- if (SUPPORTED_GRAPHICS_MODE(m))
- break;
- break;
-
- case F_PREV:
- while (--m >= modes)
- if (SUPPORTED_GRAPHICS_MODE(m))
- break;
- break;
-
- case F_REDRAW:
- continue;
-
- case F_ESC:
- return;
-
- default:
- imageError("testExecute returned %02x", r);
- break;
-
- }
- }
- }
-
- int
- testExecute()
- {
- int i;
- int r;
-
- i = 0;
-
- vidSetMode(TestMode);
- vidSetGamma(100, 100, 100);
-
- while (i >= 0 && Tests[i] != 0)
- {
- vidSetGraphicsRedraw(Tests[i]);
-
- Tests[i]();
-
- switch (r = testEnd())
- {
- case F_NEXT:
- i++;
- break;
-
- case F_PREV:
- i--;
- break;
-
- case F_ESC:
- return F_ESC;
-
- default:
- break;
- }
- }
- return r;
- }
-
- /*
- * testEnd()
- */
- int
- testEnd()
- {
- int k;
-
- for (;;)
- {
- k = kbdGetKey(K_WAIT);
-
- switch (k)
- {
- case K_ENTER:
- case 'n':
- case 'N':
- return F_NEXT;
-
- case 'p':
- case 'P':
- return F_PREV;
-
- case K_ESCAPE:
- return F_ESC;
-
- default:
- break;
- }
- }
- }
-
- /*
- * test0()
- */
- STATIC int
- test0()
- {
- int line_width, line_height, box_width, box_height, left, top;
- int total_width, total_height;
- int i, j, k, n, y;
- pixel8_t *pixels;
- int (*put_pixels)();
-
- line_width = TestModeInfo->width / 160;
- box_width = (TestModeInfo->width - line_width * 9) / 8;
- total_width = 9 * line_width + 8 * box_width;
- left = (TestModeInfo->width - total_width) / 2;
- line_height = line_width;
- box_height = (TestModeInfo->height - line_height * 7) / 6;
- total_height= 7 * line_height + 6 * box_height;
- top = (TestModeInfo->height - total_height) / 2;
-
- if (TestModeInfo->depth > 8)
- {
- line_width *= 3;
- box_width *= 3;
- total_width *= 3;
- left *= 3;
- put_pixels = vidPutPixels24;
- pixels = alloca(TestModeInfo->width * 3);
- memset(pixels, 0, TestModeInfo->width * 3);
- }
- else
- {
- put_pixels = vidPutPixels8;
- pixels = alloca(TestModeInfo->width);
- memset(pixels, 0, TestModeInfo->width);
- vidSetPalette(TestColorMap, 256);
- }
-
- vidClear(0);
- /*
- * draw the top line
- */
- y = top;
- for (i = 0; i < line_height; i++, y++)
- {
- memset(pixels + left, 255, total_width);
- put_pixels(0, y, pixels, TestModeInfo->width);
- }
-
- /*
- * draw 6 rows of boxes
- */
- for (n = 0; n < 6; n++)
- {
- for (i = 0; i < box_height; i++, y++)
- {
- pixel8_t *p = pixels + left;
-
- for (j = line_width; j < total_width; j += line_width)
- for (k = 0; k < box_width; k++)
- p[j++] = 0;
-
- put_pixels(0, y, pixels, TestModeInfo->width);
- }
-
- for (i = 0; i < line_height; i++, y++)
- {
- memset(pixels + left, 255, total_width);
- put_pixels(0, y, pixels, TestModeInfo->width);
- }
- }
-
- testShowInfo();
-
- return 0;
- }
-
- /*
- * test1()
- */
- pixel24_t p24tab[] =
- {
- { 1, 0, 0 },
- { 0, 1, 0 },
- { 0, 0, 1 },
- { 1, 1, 1 }
- };
-
- STATIC int
- test1()
- {
- int h, total_width, step, top, left, i, j, k, l;
-
- h = TestModeInfo->height / 9;
- total_width = TestModeInfo->width / 256;
- total_width *= 256;
- if (total_width == TestModeInfo->width)
- total_width -= 256;
- top = h;
- left = (TestModeInfo->width - total_width) / 2;
-
- if (TestModeInfo->depth <= 8)
- {
- int y;
- int v;
- pixel8_t *pixels = alloca(TestModeInfo->width);
-
- vidSetPalette(TestColorMap, 256);
-
- y = top;
- v = 0;
- step = total_width / 64;
-
- memset(pixels, 224, TestModeInfo->width);
-
- for (y = 0; y < top; y++)
- vidPutPixels8(0, y, pixels, TestModeInfo->width);
-
- for (i = 0; i < 4; i++)
- {
- for (j = 0; j < h; j++, y++)
- {
- pixel8_t *p = pixels + left;
-
- for (k = 0; k < 64; k++)
- for (l = 0; l < step; l++)
- *p++ = v + k;
- vidPutPixels8(0, y, pixels, TestModeInfo->width);
- }
- memset(pixels, 224, TestModeInfo->width);
- for (j = 0; j < h; j++, y++)
- vidPutPixels8(0, y, pixels, TestModeInfo->width);
-
- v += 64;
- }
- memset(pixels, 224, TestModeInfo->width);
-
- while (y < TestModeInfo->height)
- vidPutPixels8(0, y++, pixels, TestModeInfo->width);
- }
- else
- {
- int y;
- pixel24_t v, vv;
- pixel24_t *pixels = alloca(TestModeInfo->width * 3);
-
- step = total_width / 256;
-
- memset(pixels, 128, TestModeInfo->width * 3);
-
- for (y = 0; y < top; y++)
- vidPutPixels24(0, y, pixels, TestModeInfo->width);
-
- for (i = 0; i < 4; i++)
- {
- vv = p24tab[i];
-
- for (j = 0; j < h; j++, y++)
- {
- pixel24_t *p = pixels + left;
-
- v.r = 0;
- v.g = 0;
- v.b = 0;
-
- for (k = 0; k < 256; k++)
- {
- for (l = 0; l < step; l++)
- *p++ = v;
-
- v.r += vv.r;
- v.g += vv.g;
- v.b += vv.b;
- }
- vidPutPixels24(0, y, pixels, TestModeInfo->width);
- }
-
- memset(pixels, 128, TestModeInfo->width * 3);
- for (j = 0; j < h; j++, y++)
- vidPutPixels24(0, y, pixels, TestModeInfo->width);
- }
- memset(pixels, 128, TestModeInfo->width * 3);
-
- while (y < TestModeInfo->height)
- vidPutPixels24(0, y++, pixels, TestModeInfo->width);
- }
-
- testShowInfo();
-
- return 0;
- }
-
- testShowInfo()
- {
- char buf[120];
- int len;
- int x, y;
- font_t *font = DefaultFont;
-
- sprintf(buf, "%dx%d-%d",
- TestModeInfo->width, TestModeInfo->height, TestModeInfo->depth);
- len = strlen(buf);
-
- if (len > TestModeInfo->width / font->f_width)
- len = TestModeInfo->width / font->f_width;
-
- x = (TestModeInfo->width - font->f_width * len) / 2;
- y = TestModeInfo->height - font->f_height - 8;
-
- vidDrawText(x, y, buf, len, font);
-
- }
-